package com.bluegalaxy.nhb.snapi.core.util;

//import net.sf.ehcache.Cache;
//import net.sf.ehcache.Element;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cache.CacheManager;
//import org.springframework.cache.ehcache.EhCacheCacheManager;
//import org.springframework.context.annotation.Configuration;

//@Configuration
public class CacheUtils {
//    private static CacheManager manager;
//
//    @Autowired
//    public void setManager(CacheManager manager) {
//        CacheUtils.manager = manager;
//    }
//
//    public static Object get(String cacheName, Object key) {
//        Element e= cache(cacheName).get(key);
//        if(e!=null){
//            return e.getObjectValue();
//        }
//        return null;
//    }
//
//    public static void put(String cacheName, Object key, Object value, Integer ttl, Integer tti) {
//        Element e = new Element(key, value);
//        //不设置则使用xml配置
//        if (ttl != null)
//            e.setTimeToLive(ttl);
//        if (tti != null)
//            e.setTimeToIdle(tti);
//        cache(cacheName).put(e);
//    }
//
//
//    private static Cache cache(String cacheName) {
//        net.sf.ehcache.CacheManager cacheManager = ((EhCacheCacheManager) manager).getCacheManager();
//        if (!cacheManager.cacheExists(cacheName))
//            cacheManager.addCache(cacheName);
//        return cacheManager.getCache(cacheName);
//    }
}
